package com.sea.empeno.service;

import java.util.List;

import javax.management.RuntimeErrorException;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;


import com.sea.model.Contrato;
import com.sea.model.Artefacto;
import com.sea.model.Cliente;
import com.sea.model.repository.ContratoRepository;

import com.sea.util.Utilitario;


@SuppressWarnings("unused")

public class GenerarContratoService {
	
private ContratoRepository contratoRepository;
	
	private EntityManager em;
	
	public GenerarContratoService() {
		em=Utilitario.getInstance().getEntityManager();
		contratoRepository= new ContratoRepository(em);
		
		
	}
	public void generarContrato(Contrato c) throws RuntimeException{
		EntityTransaction tx=em.getTransaction();
		try {
		tx.begin();
		contratoRepository.insert(c);
		tx.commit();
		} catch (Exception e2) {
		// TODO: handle exception
		e2.printStackTrace();
		tx.rollback();
		throw new RuntimeException("No se pudo generar Contrato");
		}
	}	
	public List<Contrato> listarContrato(){
		return contratoRepository.listAll();
	}
	
	
		
	

}
